package com.nbsaas.boot.customer.rest.convert;

import com.nbsaas.boot.customer.data.entity.Customer;
import com.nbsaas.boot.customer.api.domain.request.CustomerRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.customer.data.entity.CustomerGroup;
            import com.nbsaas.boot.customer.data.entity.CustomerLevel;

/**
* 客户请求对象转换成实体对象
*/

public class CustomerEntityConvert  implements Converter<Customer, CustomerRequest> {

    @Override
    public Customer convert(CustomerRequest source) {
        Customer result = new Customer();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCustomerGroup()!=null){
                    CustomerGroup customerGroup =new CustomerGroup();
                    customerGroup.setId(source.getCustomerGroup());
                    result.setCustomerGroup(customerGroup);
                    }
                    if(source.getCustomerLevel()!=null){
                    CustomerLevel customerLevel =new CustomerLevel();
                    customerLevel.setId(source.getCustomerLevel());
                    result.setCustomerLevel(customerLevel);
                    }
        return result;
    }
}

